import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/home'

Vue.use(Router)

const routes = [
  {
    path: '/',
    component: Home,
    children: [
      {
        path: '/',
        component: resolve => require(['../views/home/homePage'], resolve)
      },
      {
        path: '/index',
        name: 'index',
        component: resolve => require(['../views/home/homePage'], resolve)
      },
      {
        path: '/tech',
        name: 'tech',
        component: resolve => require(['../views/tech/tech'], resolve)
      },
      {
        path: '/music',
        name: 'music',
        component: resolve => require(['../views/music/music'], resolve)
      },
      {
        path: '/sense',
        name: 'sense',
        component: resolve => require(['../views/sense/sense'], resolve)
      },
      {
        path: '/file',
        name: 'sortFile',
        component: resolve => require(['../views/file/sortFile'], resolve)
      },
      {
        path: '/aboutMe',
        name: 'aboutMe',
        component: resolve => require(['../views/aboutMe/aboutMe'], resolve)
      },
      {
        path: '/myApp',
        name: 'myApp',
        component: resolve => require(['../views/myApp/myApp'], resolve)
      },
      {
        path: '/articles/:articleId',
        name: 'articles',
        component: resolve => require(['../components/oneArticle'], resolve),
        props: true
      },
      {
        path: '/search/s=:searchStr',
        name: 'searchWord',
        component: resolve => require(['../views/search/search'], resolve),
        props: true
      },
      {
        path: '/search/t=:tagStr',
        name: 'searchTag',
        component: resolve => require(['../views/search/search'], resolve),
        props: true
      }
    ]
  },
  {
    path: '/admin',
    component: resolve => require(['../views/admin/admin'], resolve),
    children: [
      {
        path: '/',
        component: resolve => require(['../views/admin/techAdmin'], resolve)
      },
      {
        path: 'techAdmin',
        name: 'techAdmin',
        component: resolve => require(['../views/admin/techAdmin'], resolve)
      },
      {
        path: 'musicAdmin',
        name: 'musicAdmin',
        component: resolve => require(['../views/admin/musicAdmin'], resolve)
      },
      {
        path: 'senseAdmin',
        name: 'senseAdmin',
        component: resolve => require(['../views/admin/senseAdmin'], resolve)
      },
      {
        path: 'meAdmin',
        name: 'meAdmin',
        component: resolve => require(['../views/admin/meAdmin'], resolve)
      },
      {
        path: 'commentAdmin',
        name: 'commentAdmin',
        component: resolve => require(['../views/admin/commentAdmin'], resolve)
      },
      {
        path: 'modify/articleId=:id',
        name: 'modify',
        component: resolve => require(['../views/admin/modify'], resolve),
        props: true
      },
      {
        path: 'newArticle/type=:type',
        name: 'newArticle',
        component: resolve => require(['../views/admin/modify'], resolve),
        props: true
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: resolve => require(['../views/admin/login'], resolve)
  }
]

const router = new Router({
  mode: 'hash',
  routes,
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

export default router